package com.example.learn.hwod;

import java.util.Scanner;
import java.util.StringJoiner;

public class _34完全二叉树 {
    static String[] arr;
    static StringJoiner non_leafs = new StringJoiner(" ");
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        arr = sc.nextLine().split(" ");
        if (arr.length==1) {
            System.out.println(arr[0]);
        }else{
            dfs(0);
            System.out.println(non_leafs);
        }
    }

    private static void dfs(int root) {
        int left =root*2+1;
        int right = root*2+2;

        if (arr.length>left) {
            dfs(left);
            if (arr.length>right) {
                dfs(right);
            }
            non_leafs.add(arr[root]);
        }
    }
}
